/*
 * 原版接口
 */
import * as server from "@minecraft/server";
/*
 * 蛋白石数据
 */
import * as data_format from "./format";
/**
 * * 重置 - 海灵 - 交易列表
 * 
 * @param {server.Player} player - 玩家对象
 */
function hailingReset(player: server.Player) {
    /**
     * * 带有 权重信息 的 原始数据
     */
    const tradeTags = new Map<string, number>(
        [
            ["trophy:trade.void", 16],
            ["trophy:trade.machine_rune", 2],
            ["trophy:trade.fishery_bucket", 8],
            ["trophy:trade.mineral_products", 4],
            ["trophy:trade.heart_of_the_sea", 2],
        ]
    );
    /**
     * * 解构化 原始数据
     */
    const proto = [...tradeTags];
    /**
     * * 获取 原始数据 的 总权重
     */
    const scale = proto.reduce((acc, cur) => acc + cur[1], -1);
    /**
     * * 解析后的目标数组
     */
    const source: string[] = [];
    /**
     * * 随机索引
     */
    const index = Math.floor(Math.random() * scale);
    // 遍历 原始数据
    proto.forEach(info => { for (let index = 0; index < info[1]; index++) source.push(info[0]) });
    // 清除随机标签
    player.removeTag(source[index]);
};
/**
 * * 海灵商店
 */
export const hailing = new Map<string, data_format.SCHEDULE_NOTE>(
    [
        [
            '购置 海洋之心',
            {
                texture: 'textures/items/heartofthesea_closed',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 16 x <§l§u 鹦鹉螺壳 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:heart_of_the_sea", 1)
                ],
                attrition: [
                    new server.ItemStack("minecraft:dried_kelp", 32),
                    new server.ItemStack("minecraft:nautilus_shell", 16)
                ],
                onDone: [
                    'trophy:trade.heart_of_the_sea'
                ],
                after: hailingReset
            }
        ],
        [
            '购置 渊鲸符文',
            {
                texture: 'textures/物品贴图/模板单元/渊鲸符文',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 8 x <§l§u 空灵单元 §r>' }
                ],
                reward: [
                    new server.ItemStack("item_template:whale_rune", 1)
                ],
                attrition: [
                    new server.ItemStack("item_template:blank_template", 8),
                    new server.ItemStack("minecraft:dried_kelp", 32)
                ],
                onDone: [
                    'trophy:trade.machine_rune'
                ],
                after: hailingReset
            }
        ],
        [
            '购置 美西螈桶',
            {
                texture: 'textures/items/bucket_axolotl',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 32 x <§l§u 热带鱼 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:axolotl_bucket", 1)
                ],
                attrition: [
                    new server.ItemStack("minecraft:tropical_fish", 32),
                    new server.ItemStack("minecraft:dried_kelp", 32)
                ],
                onDone: [
                    'trophy:trade.fishery_bucket'
                ],
                after: hailingReset
            }
        ],
        [
            '购置 鳕鱼桶',
            {
                texture: 'textures/items/bucket_cod',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 8 x <§l§u 鳕鱼 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:cod_bucket", 1)
                ],
                attrition: [
                    new server.ItemStack("minecraft:cod", 8),
                    new server.ItemStack("minecraft:dried_kelp", 32)
                ],
                onDone: [
                    'trophy:trade.fishery_bucket'
                ],
                after: hailingReset
            }
        ],
        [
            '购置 河豚鱼桶',
            {
                texture: 'textures/items/bucket_pufferfish',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 8 x <§l§u 河豚鱼 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:pufferfish_bucket", 1)
                ],
                attrition: [
                    new server.ItemStack("minecraft:pufferfish", 8),
                    new server.ItemStack("minecraft:dried_kelp", 32)
                ],
                onDone: [
                    'trophy:trade.fishery_bucket'
                ],
                after: hailingReset
            }
        ],
        [
            '购置 鲑鱼桶',
            {
                texture: 'textures/items/bucket_salmon',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 8 x <§l§u 鲑鱼 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:salmon_bucket", 1)
                ],
                attrition: [
                    new server.ItemStack("minecraft:salmon", 8),
                    new server.ItemStack("minecraft:dried_kelp", 32)
                ],
                onDone: [
                    'trophy:trade.fishery_bucket'
                ],
                after: hailingReset
            }
        ],
        [
            '购置 蝌蚪桶',
            {
                texture: 'textures/items/bucket_tadpole',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 8 x <§l§u 小型垂滴叶 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:tadpole_bucket", 1)
                ],
                attrition: [
                    new server.ItemStack("minecraft:small_dripleaf_block", 8),
                    new server.ItemStack("minecraft:dried_kelp", 32)
                ],
                onDone: [
                    'trophy:trade.fishery_bucket'
                ],
                after: hailingReset
            }
        ],
        [
            '购置 热带鱼桶',
            {
                texture: 'textures/items/bucket_tropical',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 8 x <§l§u 热带鱼 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:tropical_fish_bucket", 1)
                ],
                attrition: [
                    new server.ItemStack("minecraft:tropical_fish", 8),
                    new server.ItemStack("minecraft:dried_kelp", 32)
                ],
                onDone: [
                    'trophy:trade.fishery_bucket'
                ],
                after: hailingReset
            }
        ],
        [
            '购置 海晶碎片',
            {
                texture: 'textures/items/prismarine_shard',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 16 x <§l§u 砂砾 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:prismarine_shard", 16)
                ],
                attrition: [
                    new server.ItemStack("minecraft:gravel", 16),
                    new server.ItemStack("minecraft:dried_kelp", 32)
                ],
                onDone: [
                    'trophy:trade.mineral_products'
                ],
                after: hailingReset
            }
        ],
        [
            '购置 海晶砂砾',
            {
                texture: 'textures/items/prismarine_crystals',
                refer: [
                    { text: '§r32 x <§l§u 干海带 §r> | 16 x <§l§u 砂砾 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:prismarine_crystals", 16)
                ],
                attrition: [
                    new server.ItemStack("minecraft:gravel", 16),
                    new server.ItemStack("minecraft:dried_kelp", 32)
                ],
                onDone: [
                    'trophy:trade.mineral_products'
                ],
                after: hailingReset
            }
        ],
        [
            '代加工 熟鳕鱼',
            {
                texture: 'textures/items/fish_raw',
                refer: [
                    { text: '§r8 x <§l§u 干海带 §r> | §r8 x <§l§u 生鳕鱼 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:cooked_cod", 8)
                ],
                attrition: [
                    new server.ItemStack("minecraft:cod", 8),
                    new server.ItemStack("minecraft:dried_kelp", 8)
                ],
                after: hailingReset
            }
        ],
        [
            '代加工 熟鲑鱼',
            {
                texture: 'textures/items/fish_salmon_cooked',
                refer: [
                    { text: '§r8 x <§l§u 干海带 §r> | §r8 x <§l§u 生鲑鱼 §r>' }
                ],
                reward: [
                    new server.ItemStack("minecraft:cooked_salmon", 8)
                ],
                attrition: [
                    new server.ItemStack("minecraft:salmon", 8),
                    new server.ItemStack("minecraft:dried_kelp", 8)
                ],
                after: hailingReset
            }
        ],
    ]
);